package lolnotepad;

import java.awt.Cursor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
import javax.swing.*;

/**
 *
 * @author havlicekdom@gmail.com
 */
public class Menu extends JMenuBar{
    
    public Menu(final JFrame frame, final JPanel panel, final ArrayList<String> championsP, final ArrayList<String> rolesP, final ArrayList<String> leaguesP){
        JMenu menu = new JMenu("File");
        JMenuItem item1 = new JMenuItem("New note");
        JMenuItem item2 = new JMenuItem("Read notes");
        JMenuItem item3 = new JMenuItem("Exit");
        item1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                frame.remove(panel);
                frame.revalidate();
                frame.repaint();
                Writer writer = new Writer(frame, championsP, rolesP, leaguesP);
                frame.setCursor(Cursor.getDefaultCursor());
            }
        });
        menu.add(item1);
        item2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                frame.remove(panel);
                frame.revalidate();
                frame.repaint();
                Reader reader = new Reader(frame, championsP, rolesP, leaguesP);
                frame.setCursor(Cursor.getDefaultCursor());
            }
        });
        menu.add(item2);
        menu.addSeparator();
        item3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                int answer = JOptionPane.showConfirmDialog(frame, "You want to quit?", "Quit", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                if (answer == JOptionPane.YES_OPTION) {
                    System.exit(0);
                }
            }
        });
        menu.add(item3);
        add(menu);       
    }
}
